﻿@{
    ViewBag.Title = "页面按钮";
}


<div style="width: 100%;">
    <div class="mini-toolbar" style="border-bottom: 0; padding: 0px;">
        <table style="width: 100%;">
            <tr>
                <td style="width: 100%;">
                    <a class="mini-button" iconcls="icon-add" plain="true" onclick="addRow()">增加</a>
                    <a class="mini-button" iconcls="icon-remove" plain="true" onclick="removeRow()">删除</a>
                    <a class="mini-button" iconcls="icon-save" plain="true" onclick="saveData()">保存</a>
                </td>
            </tr>
        </table>
    </div>
</div>

<div class="mini-fit" style="height: 100%;">

    <div id="datagrid1" class="mini-datagrid" style="width: 100%; height: 100%;" showpager="false"
        idfield="id" allowcelledit="true" allowcellselect="true" multiselect="true"
        editnextonenterkey="true" editnextrowcell="true">
        <div property="columns">
            <div type="indexcolumn"></div>
            <div field="ID" name="ID" headeralign="center" width="100" vtype="required">
                ID
                <input property="editor" class="mini-textbox" />
            </div>
            <div field="Text" width="120px" headeralign="center" width="100" vtype="required">
                名称
                <input property="editor" class="mini-textbox" />
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    mini.parse();

    var MID;

    var grid = mini.get("datagrid1");

    function SetData(e) {
        var f = mini.clone(e);
        MID = f.MID;
        grid.setUrl("GetMenuXML?mid=" + MID);
        grid.load();
    }

    function addRow() {
        var newRow = { name: "New Row" };
        grid.addRow(newRow, 0);
        grid.beginEditCell(newRow, "ID");
    }

    function removeRow() {
        var rows = grid.getSelecteds();
        if (rows.length > 0) {
            grid.removeRows(rows, true);
        }
    }

    function saveData() {

        grid.validate();
        if (grid.isValid() == false) {
            var error = grid.getCellErrors()[0];
            grid.beginEditCell(error.record, error.column);
            return;
        }

        var added = grid.getData();
        var jsonAdd = mini.encode(added);

        grid.loading("保存中，请稍后......");
        $.ajax({
            url: "SaveXML",
            data: { add: jsonAdd, mid: MID },
            type: "post",
            success: function (text, flag, res) {
                grid.unmask();
                if (res.responseText == "") {
                    grid.setUrl("GetMenuXML?mid=" + MID);
                    grid.reload();
                }
                else
                    top.mini.alert(res.responseText);
            },
            error: function (text, flag, res) {
                top.mini.alert(res.responseText);
            }
        });
    }





</script>

